import { Bot_msg } from "../../model/bot/bot_msg";
import server from "../../model/client/server";
import { mathType, packge } from "../../model/msgHandle/packge";
import { style_default } from "../../style/default";

class index extends packge {

    constructor() {
        super()
    }
    init(): void {
        this.addMath(mathType.math_all, '装备', ((msg: Bot_msg) => { this.list(msg) }), this)
        this.addMath(mathType.math_start, '卸下装备', ((msg: Bot_msg) => { this.takeOf(msg) }), this)
        this.addMath(mathType.math_start, '脱下装备', ((msg: Bot_msg) => { this.takeOf(msg) }), this)
        this.addMath(mathType.math_start, '查看装备', ((msg: Bot_msg) => { this.lookEquip(msg) }), this)
        
    }
    lookEquip(msg: Bot_msg){
        let lookIdx = this.getNumber(msg.getContent());
        if (lookIdx <= 0) {
            msg.repeText(`查看穿戴装备属性:查看装备 + ID`)
            return;
        }
        server.api('body/equip/Look',{idx:lookIdx},msg);
    }
    /**
     * 装备列表
     */
    async list(msg: Bot_msg){
        let req = await server.api('body/EquipList',{},msg);
        if(!req){
            return;
        }
        let list = req.list;
        let tpl = new style_default();
        tpl.setTitle('我的装备栏','⚔️')
        if(list.length > 0){
            for (let i = 0; i < list.length; i++) {
                const element = list[i];
                if(!element){
                    continue;
                }
                tpl.addLine(`[${i+1}]${element.icon}${element.name}Lv.${element.leve}`)
            }
        }else{
            tpl.addLine('你的装备栏空空如也😭')
            await tpl.addOne()
        }
 
        tpl.help('装备栏')
        tpl.toimg(msg.getFormId())
        // msg.repeText(tpl.end())
    }
    /**
     * 卸下装备
     */
    takeOf(msg: Bot_msg){
        let lookIdx = this.getNumber(msg.getContent());
        if (lookIdx <= 0) {
            lookIdx = 1;
        }
        server.api('body/EquipTakeOf', { idx: lookIdx - 1 }, msg)
    }
}
export default new index();